package com.wchen.gdoc.generate.mapping.resolver;


import com.wchen.gdoc.generate.mapping.data.ParamData;
import com.wchen.gdoc.generate.resource.structure.ObjectStructure;
import com.wchen.gdoc.generate.util.DataTypeUtil;
import com.wchen.gdoc.generate.util.StructureUtil;

/**
 * 基本类型结构解析
 *
 * @author  wchen
 * @date    2019/11/7
 */
public class BaseTypeStructureResolver extends AbsObjectStructureResolver implements TypeStructureResolver {

    public BaseTypeStructureResolver() {
        super();
    }

    /**
     * 参数解析
     *
     * @param objectStructure
     * @return
     */
    @Override
    public ParamData doResolve(ObjectStructure objectStructure) {
        if(ENABLE_DEBUG) {
            LOGGER.info(String.format("BaseTypeStructureResolver begin.  type:%s, name:%s", objectStructure.getType(), objectStructure.getSimpleName()));
        }
        String paramName = StructureUtil.getTypeAlias(objectStructure);
        String commentText = StructureUtil.getCommentText(objectStructure);
        Object paramObjValue = super.getParamValue(objectStructure.getType(), paramName);
        String structureType = DataTypeUtil.getTransType(objectStructure.getType());
        ParamData paramData = createParamData(paramName, structureType,  null, paramObjValue, commentText, Boolean.FALSE);
        return paramData;
    }

    /**
     * 判断是否支持解析器解析
     *
     * @param classType
     * @return
     */
    @Override
    public Boolean isSupport(String classType) {
        return DataTypeUtil.isBaseData(classType);
    }
}
